import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-01-15
 * Time: 10:29
 */
class Solution4 {
    public boolean containsNearbyDuplicate(int[] nums, int k) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int elem = nums[i];
            if (map.get(elem) == null) {
                map.put(elem, i);
            } else {
                Integer cur = map.get(elem);
                if (i - cur <= k) {
                    return true;
                } else {
                    map.put(elem, i);
                }
            }
        }
        return false;

    }
}




public class Test4 {
}
